﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Assets.Game.scripts.ui.models;
using FrenzyIsland.UI;

namespace Assets.Game.scripts.ui.controllers {

    [RequireComponent(typeof(HUDModel))]
    public class HUDController : MonoBehaviour {

        public GameObject buildingWidgetPrefab;
        public GameObject charactersWidgetPrefab;
        public GameObject partiesWidgetPrefab;

        /// <summary>
        /// Apre una istanza della schermata di costruzione degli edifici.
        /// </summary>
        public void onClickOpenBuildingWidget() {
            if (this.buildingWidgetPrefab != null) {
                UIRoot root = UIRoot.list[0];
                GuiManager guiManager = root.GetComponent<GuiManager>();
                GameObject widget = guiManager.openWidget(this.buildingWidgetPrefab);
                BuildingWidgetModel widgetModel = widget.GetComponent<BuildingWidgetModel>();
                if (widgetModel != null) { 
                    HUDModel model = this.GetComponent<HUDModel>();
                    widgetModel.buildingManager = model.buildingManager;
                }
            }
        }



        /// <summary>
        /// Apre una istanza della schermata di gestione dei personaggi.
        /// </summary>
        public void onClickOpenCharactersWidget() {
            if (this.charactersWidgetPrefab != null) {
                UIRoot root = UIRoot.list[0];
                GuiManager guiManager = root.GetComponent<GuiManager>();
                GameObject widget = guiManager.openWidget(this.charactersWidgetPrefab);
                CharacterListWidgetModel widgetModel = widget.GetComponent<CharacterListWidgetModel>();
                if (widgetModel != null) {
                    HUDModel model = this.GetComponent<HUDModel>();
                    widgetModel.agents = model.peopleController.SteveList;
                }
            }
        }



        /// <summary>
        /// Apre una istanza della schermata di gestione delle comitive.
        /// </summary>
        public void onClickOpenPartiesWidget() {
            if (this.partiesWidgetPrefab != null) {

                UIRoot root = UIRoot.list[0];
                GuiManager guiManager = root.GetComponent<GuiManager>();

                GameObject widget = guiManager.openWidget(this.partiesWidgetPrefab);

                PartyWidgetModel widgetModel = widget.GetComponent<PartyWidgetModel>();
                if (widgetModel != null) {
                    HUDModel model = this.GetComponent<HUDModel>();
                    widgetModel.peopleController = model.peopleController;
                }
            }
        }
    }
}
